home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / file.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  3KB  |  137 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1988 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    March 1988.
  6.  *
  7.  *    %W%    %G%
  8. */
  9. #include "fig.h"
  10. #include "resources.h"
  11. #include "func.h"
  12. #include "object.h"
  13.  
  14. #define            PROMPT        1
  15. #define            NO_PROMPT    0
  16.  
  17. extern int        figure_modified;
  18. extern char        current_file[];
  19. extern char        directory[];
  20. extern int        num_object;
  21.  
  22. edit_file(file)
  23. char    *file;
  24. {
  25.     extern F_compound    objects, saved_objects;
  26.     int        s;
  27.     F_compound    c;
  28.  
  29.     if (*file == 0) {
  30.         put_msg("Empty name");
  31.         return;
  32.         }
  33.     c.arcs = NULL;
  34.     c.compounds = NULL;
  35.     c.ellipses = NULL;
  36.     c.lines = NULL;
  37.     c.splines = NULL;
  38.     c.texts = NULL;
  39.     c.next = NULL;
  40.     set_temp_cursor(&wait_cursor);
  41.     s = read_fig(file, &c);
  42.     if (s == 0) {        /* Successful read */
  43.         clean_up();
  44.         (void)strcpy(current_file, file);
  45.         saved_objects = objects;
  46.         objects = c;
  47.         redisplay_canvas();
  48.         put_msg("Edit \"%s\" %d objects", file, num_object);
  49.         set_action(F_EDIT);
  50.         }
  51.     else if (s == ENOENT) {
  52.         clean_up();
  53.         saved_objects = objects;
  54.         objects = c;
  55.         redisplay_canvas();
  56.         put_msg("\"%s\" new file", file);
  57.         (void)strcpy(current_file, file);
  58.         set_action(F_EDIT);
  59.         }
  60.     else if (s > 0)
  61.         read_fail_message(file, s);
  62.     reset_cursor();
  63.     }
  64.  
  65. read_file(file)
  66. char    *file;
  67. {
  68.     extern F_compound    objects, saved_objects, object_tails;
  69.     int        s;
  70.     F_compound    c;
  71.  
  72.     if (*file == 0) {
  73.         put_msg("Empty name");
  74.         return;
  75.         }
  76.  
  77.     c.arcs = NULL;
  78.     c.compounds = NULL;
  79.     c.ellipses = NULL;
  80.     c.lines = NULL;
  81.     c.splines = NULL;
  82.     c.texts = NULL;
  83.     c.next = NULL;
  84.     set_temp_cursor(&wait_cursor);
  85.     s = read_fig(file, &c);
  86.     if (s == 0) {        /* Successful read */
  87.         clean_up();
  88.         saved_objects = c;
  89.         tail(&objects, &object_tails);
  90.         append_objects(&objects, &saved_objects, &object_tails);
  91.         pw_batch_on(canvas_pixwin);
  92.         redisplay_canvas();
  93.         pw_batch_off(canvas_pixwin);
  94.         put_msg("File \"%s\" %d objects", file, num_object);
  95.         set_action_object(F_CREATE, O_ALL_OBJECT);
  96.         }
  97.     else if (s > 0)
  98.         read_fail_message(file, s);
  99.     reset_cursor();
  100.     }
  101.  
  102. save_and_exit(file)
  103. char    *file;
  104. {
  105.     if (0 == write_file(file, PROMPT)) quit();
  106.     }
  107.  
  108. save_current_file()
  109. {
  110.     return(write_file(current_file, NO_PROMPT));
  111.     }
  112.  
  113. save_file(file)
  114. char    *file;
  115. {
  116.     return(write_file(file, PROMPT));
  117.     }
  118.  
  119. status()
  120. {
  121.     extern char    *getwd();
  122.  
  123.     if (*directory == NULL) {
  124.         if (NULL == getwd(directory)) {
  125.         put_msg("%s", directory);    /* err msg is in directory */
  126.         *directory = '\0';
  127.         return;
  128.         }
  129.         }
  130.  
  131.     if (*current_file == '\0')
  132.         put_msg("No file; directory \"%s\"", directory);
  133.     else
  134.         put_msg("file \"%s\" %s; directory \"%s\"", current_file,
  135.             (figure_modified ? "[modified]" : ""), directory);
  136.     }
  137.